package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.vo.ShopVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ConfigShops;
import com.ruoyi.system.service.IConfigShopsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商铺管理Controller
 * 
 * @author YuKunXu
 * @date 2024-02-28
 */
@RestController
@RequestMapping("/system/shops")
public class ConfigShopsController extends BaseController
{
    @Autowired
    private IConfigShopsService configShopsService;

    /**
     * 查询商铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:shops:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopVo configShops)
    {
        startPage();
        List<ShopVo> list = configShopsService.selectConfigShopsList(configShops);
        return getDataTable(list);
    }

    /**
     * 导出商铺管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:shops:export')")
    @Log(title = "商铺管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopVo configShops)
    {
        List<ShopVo> list = configShopsService.selectConfigShopsList(configShops);
        ExcelUtil<ShopVo> util = new ExcelUtil<ShopVo>(ShopVo.class);
        util.exportExcel(response, list, "商铺管理数据");
    }

    /**
     * 获取商铺管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:shops:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(configShopsService.selectConfigShopsById(id));
    }

    /**
     * 新增商铺管理
     */
    @PreAuthorize("@ss.hasPermi('system:shops:add')")
    @Log(title = "商铺管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConfigShops configShops)
    {
        return toAjax(configShopsService.insertConfigShops(configShops));
    }

    /**
     * 修改商铺管理
     */
    @PreAuthorize("@ss.hasPermi('system:shops:edit')")
    @Log(title = "商铺管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConfigShops configShops)
    {
        return toAjax(configShopsService.updateConfigShops(configShops));
    }

    /**
     * 删除商铺管理
     */
    @PreAuthorize("@ss.hasPermi('system:shops:remove')")
    @Log(title = "商铺管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(configShopsService.deleteConfigShopsByIds(ids));
    }

    /**
    *
    * @author YuKunXu
     * 获取同一楼层的商铺信息的集合
     * @return com.ruoyi.common.core.domain.AjaxResult
    */
    @GetMapping("/floors")
    public AjaxResult selectAll(@RequestParam("buildId") Integer id){
        return success(configShopsService.selectAllByFloor(id));
    }

    /**
    *
    * @author YuKunXu
     * 商业区和楼栋信息级联选择器
     * @return com.ruoyi.common.core.domain.AjaxResult
    */
    @GetMapping("/allBuild")
    public AjaxResult selectAllBuild(){
        return success(configShopsService.selectAllBuild());
    }
}
